package com.wxtt.android.config;

import android.app.Activity;
import android.content.Context;

import com.bmob.BmobProFile;
import com.bmob.btp.callback.UploadListener;
import com.fast.dev.frame.AbstractApplication;
import com.fast.dev.frame.HttpUtils;
import com.fast.dev.frame.http.callback.BaseHttpCallBack;
import com.fast.dev.frame.http.RequestParams;
import com.fast.dev.frame.utils.LogUtils;
import com.sina.weibo.sdk.auth.Oauth2AccessToken;
import com.three.WeiboUtils;
import com.wxtt.android.bean.SuggestBean;
import com.wxtt.android.listener.BaseListener;
import java.io.File;
import cn.bmob.v3.datatype.BmobFile;
import cn.bmob.v3.listener.BmobUpdateListener;
import cn.bmob.v3.listener.SaveListener;
import cn.bmob.v3.update.BmobUpdateAgent;

/**
 * 说明：业务配置类
 * <p/>
 * 作者：fanly
 * <p/>
 * 时间：2015/12/28 14:48
 * <p/>
 * 版本：verson 1.0
 */
public final class ApiConfig {
    /**
     * 说明：禁止实例化
     */
    private ApiConfig(){}

    /**
     * 说明：上传Bmob崩溃日志
     * @param file
     */
    public static void uploadBmobFile(File file){
        BmobProFile.getInstance(AbstractApplication.getContext()).upload(file.getAbsolutePath(), new UploadListener() {
            @Override
            public void onSuccess(String s, String s1, BmobFile bmobFile) {
                LogUtils.v("bmob 文件上传成功：" + s);
            }

            @Override
            public void onProgress(int i) {
                LogUtils.v(i);
            }

            @Override
            public void onError(int i, String s) {
                LogUtils.e(i+"  "+s);
            }
        });
    }

    /**
     * 说明：查询微信精选
     * @param pno 当前页数
     * @param ps 每页条数
     * @param callback 回调接口
     */
    public static void queryWXJX(int pno,int ps,BaseHttpCallBack callback){
        RequestParams params = new RequestParams();
        params.put("pno",pno);
        params.put("ps", ps);
        params.put("key",ConstantConfig.WXTT_APPID);
        HttpUtils.post(ConstantConfig.REQUEST_METHOD.QUERY, params, callback);
    }

    /**
     * 说明：查询视频数据
     * @param page 当前页数
     * @param count 每页条数
     * @param category 关键字
     * @param callback 回调接口
     */
    public static void queryVideo(int page,int count,String category,BaseHttpCallBack callback){
        RequestParams params = new RequestParams();
        params.put("client_id",ConstantConfig.YK_APP_KEY);
        params.put("keyword",category);
        params.put("period","today");
        params.put("orderby","published");
        params.put("public_type","all");
        params.put("paid","0");
        params.put("page",page);
        params.put("count", count);
        params.put("streamtypes", 1);
        HttpUtils.get(ConstantConfig.REQUEST_METHOD.VIDEO, params, callback);
    }

    /**
     * 说明：查询笑话
     * @param page 当前页
     * @param count 每页条数
     * @param callBack
     */
    public static void queryJoke(int page,int count,BaseHttpCallBack callBack){
        RequestParams params = new RequestParams();
        params.put("page",page);
        params.put("pagesize", count);
        params.put("key", ConstantConfig.JOKE_APPID);
        HttpUtils.get(ConstantConfig.REQUEST_METHOD.JOKE, params, callBack);
    }

    /**
     * 说明：发送意见反馈
     * @param bean
     * @param listener
     */
    public static void sendSuggest(Context context,SuggestBean bean, final BaseListener listener){
        bean.save(context, new SaveListener() {
            @Override
            public void onSuccess() {
                if (listener != null) {
                    listener.success();
                }
            }

            @Override
            public void onFailure(int i, String s) {
                if (listener != null) {
                    listener.fail(i, s);
                }
            }
        });
    }

    /**
     * 说明：检查更新
     */
    public static void checkUpdate(Activity activity){
        BmobUpdateAgent.setUpdateOnlyWifi(SpConfig.isWifiUpdate());
        BmobUpdateAgent.update(activity);
    }

    /**
     * 说明：手动检查更新
     */
    public static void checkUpdate(BmobUpdateListener listener){
        BmobUpdateAgent.setUpdateListener(listener);
    }

    /**
     * 说明：获取微博用户信息
     * @param token
     * @param callBack
     */
    public static void getWeiboUserInfo(Oauth2AccessToken token,BaseHttpCallBack callBack){
        RequestParams params = new RequestParams();
        params.put("access_token",token.getToken());
        params.put("uid", token.getUid());
        params.put("key", ConstantConfig.JOKE_APPID);
        HttpUtils.get(ConstantConfig.REQUEST_METHOD.WEIBO_USER_INFO, params, callBack);
    }

    /**
     * 说明：注销新浪微博登录
     * @param callBack
     */
    public static void loginOutWeibo(BaseHttpCallBack callBack){
        RequestParams params = new RequestParams();
        params.put("access_token",WeiboUtils.getToken().getToken());
        HttpUtils.get(ConstantConfig.REQUEST_METHOD.WEIBO_LOGIN_OUT, params, callBack);
    }

}
